<?php
//ini_set("display_errors" , 1);
my_component_load('testing' , false);
my_component_load('xl_builder' , false);
my_component_load('paging' , false); 
my_component_load('spd_baru');
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;

$modulname = "Personalia _BN_ Perjalanan Dinas";
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if($task == "create_page"){ 
		$validatepost = form_spd_validate();
		if($validatepost){
			$content = message_multi_error($validatepost); 
			$content .= form_spd($id);
			generate_my_web($content, '' ,'plain.php' );
			exit;
		}else{
			insert_spd_baru();
			if(isset($_POST['create_again']))
				my_direct($_SERVER['HTTP_REFERER']);
			else
				generate_my_web("Created!", '' ,'plain.php' );
			exit;
		}

	}elseif($task == "excel_range_page"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=masterpenggajian_detail".rand().".xls");
		echo download_excel_range();
		exit;

	}elseif($task == "setbiaya"){
		submit_biaya();
		if(isset($_POST['create_again']))
			my_direct('index.php?com='.$_GET['com'].'&task=create_page');
		else
			generate_my_web("Created!", '' ,'plain.php' );
		exit;
	}

}else{
	if($task == "detail"){ 
		$title= "Detail informasi perjalanan dinas" ;
		facebox_page('index.php?com='.$_GET['com'].'&task=detail_page&id='.$id , $title , 260	); 

	}elseif($task == "excel_range"){
		$title= "Download excel berdasarkan waktu" ;
		facebox_page('index.php?com='.$_GET['com'].'&task=excel_range_page&id='.$id , $title , 172	); 
		
	}elseif($task == "excel_range_page"){ 
		$content = xls_range_page( );
		generate_my_web($content, '' ,'plain.php' );
		exit;
			
	}elseif($task == "create"){
		$title= "Tambah data perjalanan dinas" ;
		facebox_page('index.php?com='.$_GET['com'].'&task=create_page&id='.$id , $title , 430	); 
		
	}elseif($task == "create_page"){ 
		$content = form_spd($id);
		generate_my_web($content, '' ,'plain.php' );
		exit;
	}elseif($task == "delete"){
		delete_spd($id);
		my_direct($_SERVER['HTTP_REFERER'] );
	}elseif($task == "detail_page"){	
		$content = detail_spd($id);
		generate_my_web($content, '' ,'plain.php' );
		exit;
	}elseif($task == "cetak"){
		echo print_out($id);
		exit;
	}elseif($task == "plaincetak"){
		@ob_end_clean(); 
		echo'<pre>';
		echo print_plain();
		exit;
	}elseif($task == "excel"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=spd_export".rand().".xls");
		echo excel_report();
		exit;	
	}elseif($task == "plaincetak_det"){
		@ob_end_clean(); 
		echo'<pre>';
		echo print_plain_det($id);
		exit;
	}elseif($task == "setbiaya"){
		
		$content = set_biaya($id);
		generate_my_web($content, '' ,'plain.php' );
		exit;
	}elseif($task == "excel_det"){
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=masterpenggajian_detail".rand().".xls");
		echo excel_report_det($id);
		exit;						
	}else{
		$pagename = $modulname;
		load_facebox_script();
		$content = list_spd();
	}
}
generate_my_web($content, $pagename  );
?>